#define _CRT_SECURE_NO_WARNINGS 1

class Solution
{
public:
    bool backspaceCompare(string s, string t)
    {
        vector<int> s1;

        for (auto ch : s)
        {
            if (s1.size() > 0 && ch == '#') s1.pop_back();
            else {
                if (ch != '#')
                    s1.push_back(ch);
            }
        }

        vector<int> t1;

        for (auto ch : t)
        {
            if (t1.size() > 0 && ch == '#') t1.pop_back();
            else {
                if (ch != '#')
                    t1.push_back(ch);
            }
        }

        int n = s1.size();
        int m = t1.size();
        if (n > m || n < m) return false;

        for (int i = 0; i < n; i++)
        {
            if (t1[i] != s1[i]) return false;
        }

        return true;

    }
};